package gold.digger;

import gold.utils.InputUtil;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1823 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findTheWinner(int n, int k) {
            Queue<Integer> queue = new LinkedList<>();
            for (int i = 1; i < n + 1; i++) queue.offer(i);
            for (int i = 0; i < n - 1; i++) {
                for (int j = 0; j < k - 1; j++) {
                    queue.offer(queue.poll());
                }
                queue.poll();
            }

            return queue.poll();
        }
    }

    public void run() {
        System.out.println(new Solution().findTheWinner(5, 2));
        System.out.println(new Solution().findTheWinner(6, 5));
    }

    public static void main(String[] args) throws Exception {
        LC1823 an = new LC1823();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
